#include "TwApplicationPCH.h"
#include "TwDefines.h"
#include "TwTexture.h"
#include "TwDeviceManager.h"

TwTexture::TwTexture() :
mD3DTexture(NULL)
{
	ZeroMemory(&mSurfaceDesc, sizeof(mSurfaceDesc));
}

TwTexture::~TwTexture()
{
	TwSafeRelease(mD3DTexture);
}

bool TwTexture::loadFromFile(LPCSTR filename)
{
	TwSafeRelease(mD3DTexture);
	if (FAILED(D3DXCreateTextureFromFile(TwDeviceManager::getDevice(), filename, &mD3DTexture)))
		return false;
	
	assert(mD3DTexture->GetLevelCount() > 0);
	mD3DTexture->GetLevelDesc(0, &mSurfaceDesc);

	return true;
}

IDirect3DTexture9* TwTexture::getTexture() const
{
	return mD3DTexture;
}

unsigned int TwTexture::getWidth() const
{
	return mSurfaceDesc.Width;
}

unsigned int TwTexture::getHeight() const
{
	return mSurfaceDesc.Height;
}